<?php
/**
 * Created by PhpStorm.
 * User: 曹旺
 * Date: 2018-04-13
 * Time: 16:35
 */
namespace app\index\controller;
class Log
{
    public static function fileLog($data, $name)
    {
        $file = fopen(Log::getPath() . '/' . $name, 'a');
        fwrite($file, date('Y-m-d H:i:s') . PHP_EOL);
        if (is_array($data) || is_object($data)) {
            foreach ($data as $k => $v) {
                fwrite($file, $k . ':' . $v . ';');
            }
        } else {
            fwrite($file, $data);
        }
        fwrite($file, PHP_EOL . PHP_EOL);
        fclose($file);
    }

    /**
     * 获取日志文件路径
     * author leesin.
     * date 2018/3/22
     */
    public static function getPath()
    {
        $path = RUNTIME_PATH . '/pay-log/' . date('Ym-d');
        if (!is_dir($path)) {
            mkdir($path, 0777, true);
            chmod($path, 0777);
        }
        return $path;
    }
}